package com.zhangzhan.controller;

import com.zhangzhan.domain.commcon.ResponseResult;
import com.zhangzhan.domain.dto.SaveMenuDto;
import com.zhangzhan.domain.dto.UpdateMenuDto;
import com.zhangzhan.domain.vo.MenuTreeSelectVO;
import com.zhangzhan.domain.vo.RoleMenuTreeselectVO;
import com.zhangzhan.service.MenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author 张一恒
 * @version 1.0
 * @description:
 * @date 2022/12/7 11:00
 */
@RestController
@RequestMapping("/system/menu")
public class SystemMenuController {

    @Autowired
    MenuService menuService;

    /**
     * @description 查询接口
     * @param status
     * @param menuName
     * @return com.zhangzhan.domain.commcon.ResponseResult
     * @author 31115
     * @date 2022/12/7 11:22
     */
    @GetMapping("/list")
    public ResponseResult listMenu(String status,String menuName){
        return menuService.listMenu(status, menuName);
    }

    /**
     * @description 新增
     *
     * @return com.zhangzhan.domain.commcon.ResponseResult
     * @author 31115
     * @date 2022/12/7 11:22
     */
    @PostMapping
    public ResponseResult saveMenu(@RequestBody SaveMenuDto saveMenuDto){
        return menuService.saveMenu(saveMenuDto);
    }

    /**
     * @description 修改前回显
     *
     * @return com.zhangzhan.domain.commcon.ResponseResult
     * @author 31115
     * @date 2022/12/7 13:44
     */
    @GetMapping("{id}")
    public ResponseResult rowBackMenu(@PathVariable Long id){
        return menuService.rowBackMenu(id);
    }

    /**
     * @description 修改菜单
     * @param updateMenuDto
     * @return com.zhangzhan.domain.commcon.ResponseResult
     * @author 31115
     * @date 2022/12/7 14:11
     */
    @PutMapping
    public ResponseResult updateMenu(@RequestBody UpdateMenuDto updateMenuDto){
        return menuService.updateMenu(updateMenuDto);
    }

    /**
     * @description 删除菜单
     * @param menuId
     * @return com.zhangzhan.domain.commcon.ResponseResult
     * @author 31115
     * @date 2022/12/7 14:14
     */
    @DeleteMapping("{menuId}")
    public ResponseResult deleteMenu(@PathVariable Long menuId){
        return menuService.deleteMenu(menuId);
    }

    /**
     * @description 获取菜单树接口
     *
     * @return com.zhangzhan.domain.commcon.ResponseResult
     * @author 31115
     * @date 2022/12/7 15:20
     */
    @GetMapping("/treeselect")
    public ResponseResult<MenuTreeSelectVO> treeselect(){
        return menuService.treeselect();
    }

    /**
     * @description 加载对应角色菜单列表树接口
     * @param id
     * @return com.zhangzhan.domain.commcon.ResponseResult<com.zhangzhan.domain.vo.RoleMenuTreeselectVO>
     * @author 31115
     * @date 2022/12/7 22:32
     */
    @GetMapping("/roleMenuTreeselect/{id}")
    public ResponseResult<RoleMenuTreeselectVO> roleMenuTreeselect(@PathVariable Long id){
        return menuService.roleMenuTreeselect(id);
    }
}
